<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
        <div th:replace="include/bootstrap :: bootstrap"></div>
</head>
<body>
<div th:replace="include/PaperNav :: PaperNav"></div>
<script th:inline="javascript">
    var single = [[${exam}]];
    var testtime = single.testtime;



        var examTime = testtime * 60;
        var useTime = 0, remainTime = examTime;

    // 显示使用时间和剩余时间
    function showCount(){
        if(remainTime==0){
            document.getElementById("myForm").submit();
        }
        useTime+=1;
        remainTime-=1;
        var hourU=Math.floor(useTime/3600);
        var minuteU=Math.floor((useTime-hourU*3600)/60);
        var secondU=Math.floor(useTime-hourU*3600-minuteU*60);
        document.getElementById("useTime").innerHTML=format(hourU)+":"+format(minuteU)+":"+format(secondU);

        var hourR=Math.floor(remainTime/3600);
        var minuteR=Math.floor((remainTime-hourR*3600)/60);
        var secondR=Math.floor(remainTime-hourR*3600-minuteR*60);
        document.getElementById("remainTime").innerHTML=format(hourR)+":"+format(minuteR)+":"+format(secondR);
    }

    // 格式化日期数字
    function format(timeNumber){
        if(timeNumber==0){
            return "00";
        }else if(timeNumber<10){
            return "0"+timeNumber;
        }else{
            return timeNumber;
        }
    }
    window.setInterval("showCount()",1000);

    window.onload = function(){
        var nowDate = new Date();
        var str = nowDate.getFullYear()+"-"+(nowDate.getMonth() + 1)+"-"+nowDate.getDate()+" "+nowDate.getHours()+":"+nowDate.getMinutes()+":"+nowDate.getSeconds();
        document.getElementById("tjtime").value=str;
    }
  //$('#tjtime').val(tjtime);
</script>
<main class="container">
    <div class="panel panel-default">
        <div class="panel-heading text-center">
            <h3 class="panel-title" th:text="${exam.getPname()}"></h3>
        </div>
        <div class="panel-body">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <input type="hidden" th:value="${exam.testtime}" id="testtime">
                        <p data-toggle="collapse" data-parent="#accordion">一，单选题（共 <span th:text="${cont}"></span> 题，每题<span id="" th:text="${exam.singlecore}"></span>分）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;考试时间：<strong><span th:text="${exam.testtime}"></span>分钟</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            计时：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font id="useTime" style="font-weight: bold;"></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            剩余时间：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font id="remainTime" style="font-weight: bold;color: red"></font></p>
                    </h4>
                </div>
                <form th:action="@{/PaperScore}" method="post" role="myForm">
                <input type="hidden" name="eid" th:value="${exam.eid}">
                <input type="hidden" name="pname" th:value="${exam.pname}">
                    <input type="hidden" name="userid" th:value="${session.lis}">
                    <input type="hidden" id="tjtime" name="tjtime" value=""/>
                <div id="Radio" class="panel-collapse collapse in">
                    <div class="panel-body">
                            <ol type="1">
                                <div class="subject" th:each="singles:${session.single}">
                                   <li th:text="${singles.scontent}"></li>
                                     <ol style="list-style:none;">
                                        <input type="hidden" name="sid" th:value="${singles.sid}">
                                         <li><label><input type="radio" value="A" class="rad" th:name="${singles.sid}" th:text="'A:'+${singles.sa}"></label></li>
                                         <li><label><input type="radio" value="B" class="rad" th:name="${singles.sid}" th:text="'B:'+${singles.sb}"></label></li>
                                         <li><label><input type="radio" value="C" class="rad" th:name="${singles.sid}" th:text="'C:'+${singles.sc}"></label></li>
                                         <li><label><input type="radio" value="D" class="rad" th:name="${singles.sid}" th:text="'D:'+${singles.sd}"></label></li>
                                     </ol>
                                </div>
                            </ol>

                        <button class="btn btn-success" type="submit" onclick="getValue()">交卷</button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
</main>
<script th:inline="javascript">
    var cont = [[${cont}]];
    var cont1 =[[${cont1}]];
    function getValue(){
        //单选
        var radio = document.getElementsByClassName("rad");

        var studentkeys = new Array();
        for (i =0; i<radio.length; i++) {
            if (radio[i].checked) {
                console.log(radio[i].value);
                studentkeys.push(radio[i].value);
            }
        }

        if( studentkeys.length < cont||studentkeys.length < cont1){
            confirm("还有未选择的题目,是否提交？")
        }
        else{
            confirm('将提交该试卷，是否继续?');

        }
    }
</script>
</body>
</html>